package properties1;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.nio.charset.Charset;
import java.util.Properties;
import java.util.Set;

public class PropertiesTest1 {
    public static void main(String[] args) throws Exception {
        // 创建一个properties对象出来
        Properties properties = new Properties();
        System.out.println(properties);

        // 开始加载属性文件中的键值对数据到properties对象中
        properties.load(new FileReader("src\\dome.properties"));
        System.out.println(properties);

        // 根据建取值
        System.out.println(properties.getProperty("张家动"));
        System.out.println(properties.getProperty("王彦博"));
        System.out.println();

        // 便利全部键和值
        Set<String> keys = properties.stringPropertyNames();
//        for (String key : keys) {
        keys.forEach(key -> {
            String value = properties.getProperty(key);
            System.out.println(key + "-->" + value);



            properties.forEach((k,v) -> {
                System.out.println(k + "-->" + v);
            });
        });
    }
}
